<?php

namespace app\manage\controller;

use core\libs\db;
use core\libs\input;

class basic extends base {
    // 初始化
    public function __init() {
        // 是否有权限
        $this->is_level($this->baseClass . "_list");
        if(in_array($this->baseAction, ["submit"])) {
            $this->is_level($this->baseClass . "_edit");
        }
    }

    // 列表
    public function index() {
        $row = db::fetch('basic');
        $consts = explode("||", $row['basic_name']);
        foreach($consts as $key => $val) {
            $consts[$key] = str_replace("\"", "&#34;", $consts[$key]);
            $consts[$key] = str_replace("'", "&#39;", $consts[$key]);
        }

        $this->assign("consts", $consts);
        $this->display("basic");
    }

    // 分类添加/修改
    public function submit() {
		//预处理数据
		$form_datas = array(
			'basic_name' => implode("||", input::request("const_name"))
		);
        foreach($form_datas as $key => $val) {
            $form_datas[$key] = html_entity_decode($val);
        }

		$res_const = db::fetch("basic");
		if($res_const) {
			db::update('basic', $form_datas);
		}
		else {
			db::insert('basic', $form_datas);	
		}
        
		alert('内容修改成功!', U("basic"));
    }
}